#include "converters.h"
#include <iostream>

void ConvertRB2BtoRB (const RuleBase2B& rb2b, RuleBase& rb)
	{
		rb.instance.clear();
		rb.ruleSize = rb2b.getInstanceSize();
		rb.conflictNum = rb2b.getConflictNum();
		rb.repeatationNum = rb2b.getRepeatationNum();
		rb.separability = -1;
		rb.separabilityIsValid = false;
		LongInstance2 toBeAdded;
		for (int i = 0; i < rb2b.getInstanceNum(); ++i)
		{
			ConvertLI2BtoLI2(rb2b.instance[i], toBeAdded);
			//std::cout << "Now adding the LongInstance2 object: ";
			//toBeAdded.printDetail();
			rb.instance.push_back(toBeAdded);
		}
};

void ConvertLI2BtoLI2 (const LongInstance2B& li2b, LongInstance2& li2)
{
	li2.coordinate.clear();
	Neighborhood2* nb2ptr;
	for (int i = 0; i < (int) li2.neighborhood.size(); ++i)
	{
		nb2ptr = (Neighborhood2*) li2.neighborhood[i];
		delete nb2ptr;
	}
	li2.neighborhood.clear();
	li2.conflictNum = li2b.conflictNum;
	li2.label = li2b.label;
	li2.totalHash = li2b.totalHash;
	for (int i = 0; i < (int) li2b.coordinate.size(); ++i)
		li2.coordinate.push_back(li2b.coordinate[i]);

	//Neighborhood* nbptr;
	//for (int i = 0; i < (int) li2b.neighborhood2.size(); ++i)
	//{
	//	nbptr = new Neighborhood;
	//	ConvertNB2toNB(li2b.neighborhood2[i], *nbptr);
	//	li2.neighborhood.push_back(nbptr);
	//}

	Neighborhood* nbptr; //LongIntance2 already has pointers to Neighborhood2 objects.
	//Neighborhood2* nb2ptr_garbagecollector;
	for (int i = 0; i < (int) li2b.neighborhood2.size(); ++i)
	{
		nbptr = new Neighborhood2 (li2b.neighborhood2[i]);
		//ConvertNB2toNB(li2b.neighborhood2[i], *nbptr);
		li2.neighborhood.push_back(nbptr);

		//delete nbptr;
	}

}


void ConvertNB2toNB  (const Neighborhood2& nb2, Neighborhood& nb)
{
	if (nb.feature != NULL)
		delete[] nb.feature;
	nb.feature = new int[nb2.getSize()];
	nb.hash = nb2.hash;

	for (int i = 0; i < nb2.getSize(); ++i)
		nb.feature[i] = nb2.getFeature(i);
}